<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>图片切换</title>
</head>
<body>
<div>
    <img src="images/1.png" id="flower">
    <br>
    <button id="prev">上一张</button>
    <button id="next">下一张</button>
</div>

<script>
    //1.获取事件源，需要的标签
    var flower=document.getElementById('flower');
    var prevBtn=document.getElementById('prev');
    var nextBtn=document.getElementById('next');

    //索引
    var minIndex=1,maxIndex=7,currentIndex = minIndex;
    //2.监听按钮的点击
    nextBtn.onclick=function (){
        if(currentIndex==maxIndex){
            currentIndex=minIndex;
        }else {
            currentIndex++;
        }
        flower.setAttribute('src','images/${currentIndex}.png')
    }

    prevBtn.onclick=function (){
        if(currentIndex==minIndex){
            currentIndex=maxIndex;
        }else {
            currentIndex--;
        }
        flower.setAttribute('src','images/${currentIndex}.png')
    }
</script>
</body>
</html>